package com.syl.service.shiro;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;


/**
 * Created by edgar on 2017/4/5.
 */

public class MyRealm extends AuthorizingRealm {
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        return null;
    }

//    @Resource
//    private UserService userService;
//
//    /**
//     * 权限认证
//     * @param principalCollection
//     * @return
//     */
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//        String username = principalCollection.getPrimaryPrincipal().toString();
//        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//        DBContextHolder.setDbType(DBContextHolder.DB_TYPE_R);
//        Set<String> roleNames = userService.findRoles(username);
//        Set<String> permissionNames = userService.findPermissions(username);
////        info.setRoles(roleNames);
////        info.setStringPermissions(permissionNames);
//        return info;
//    }
//
//    /**
//     * 登陆验证
//     * @param authenticationToken
//     * @return
//     * @throws AuthenticationException
//     */
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//        String username = authenticationToken.getPrincipal().toString();
//        System.out.println("sssssssssssssssss"+username);
//        DBContextHolder.setDbType(DBContextHolder.DB_TYPE_R);
//        User user = userService.findUserByUserName(username);
//        String a="ss";
//        if(user!=null){
//            AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getUsername(),user.getPassword(),this.getName());
//            return authenticationInfo;
//        }
//        return null;
//    }
//
//    public String getName() {
//        return this.getClass().getName();
//    }
}
